package com.cyneck.demo.model;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * <p>Description: ResponseEntity</p>
 *
 * @author Eric Lee
 * @version v1.0.0
 * @since 2020/9/15 11:15
 **/

@Data
public class ApiResponseEntity<T> implements Serializable {


    private Integer status;

    private String message;

    private T data;


    public ApiResponseEntity(Integer status, String message) {
        this.status = status;
        this.message = message;
    }

    public ApiResponseEntity(Integer status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public static <T> ApiResponseEntity<T> success() {
        return new ApiResponseEntity(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase());
    }

    public static <T> ApiResponseEntity<T> success(T data) {
        return new ApiResponseEntity(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), data);
    }

    public static <T> ApiResponseEntity<T> success(String msg) {
        return new ApiResponseEntity(HttpStatus.OK.value(), msg);
    }

    public static <T> ApiResponseEntity<T> success(String msg, T data) {
        return new ApiResponseEntity(HttpStatus.OK.value(), msg, data);
    }

    public static <T> ApiResponseEntity<T> fail(String msg) {
        return new ApiResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
    }

    public static <T> ApiResponseEntity<T> fail(HttpStatus status, String msg) {
        return new ApiResponseEntity(status.value(), msg);
    }

}
